package atguigu.export;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.jxls.common.Context;
import org.jxls.transform.Transformer;
import org.jxls.util.JxlsHelper;

public class Main {

	
	public static void main(String[] args) {
		Context context = new Context();
		
		Employee employee = new Employee();
		employee.setName("王大毛");
		employee.setNo("ST20210624");
		employee.setGroup("一组");
		
		context.putVar("name", employee.getName());
		context.putVar("no", employee.getNo());
		context.putVar("group", employee.getGroup());
        
        JxlsHelper jxlsHelper = JxlsHelper.getInstance();
        InputStream resourceAsStream = Employee.class.getResourceAsStream("Employee.xlsx");
        FileOutputStream os;
		try {
			os = new FileOutputStream(new File("d://Employee"+System.currentTimeMillis()+".xlsx"));
			Transformer transformer  = jxlsHelper.createTransformer(resourceAsStream, os);
			jxlsHelper.processTemplate(context, transformer);
			os.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
